package com.snowdragon.system.controller;

import com.snowdragon.common.core.constants.HttpConstants;
import com.snowdragon.common.core.controller.BaseController;
import com.snowdragon.common.core.domain.po.R;
import com.snowdragon.common.core.domain.vo.LoginUserVO;
import com.snowdragon.system.domain.sysuser.dto.SysUserSaveDTO;
import com.snowdragon.system.domain.sysuser.vo.SysUservo;
import com.snowdragon.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员用户API")
@RequiredArgsConstructor
public class SysUserController extends BaseController {

    private final ISysUserService sysUserService;

    @PostMapping("/login")
    public R<String> login(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        log.info("登录");
        return sysUserService.login(sysUserSaveDTO);
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(sysUserService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }


    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员用户")
    public R add(@Validated @RequestBody SysUserSaveDTO sysUserSaveDTO) {
        log.info("新增用户");
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "用户ID")
    })
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")

    public R delete(@PathVariable Long userId) {
        return null;
    }

    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "用户性别")
    })
    @ApiResponse(responseCode = "1000", description = "成功获取用户信息")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")

    public R<SysUservo> detail(@RequestParam Long userId) {
        return null;
    }

    @GetMapping("/hi")
    public R<String> hi(){
        return R.ok("hello");
    }
}
